package code.easy.refresh

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.layout.Placeable
import kotlin.math.max

/**
 * 内容从底部开始绘制
 */
@Composable
fun BottomColumn(modifier: Modifier = Modifier, content: @Composable () -> Unit) {
    Layout(content, modifier) { measurableList, constraints ->
        var width = 0
        var height = 0
        val placeableList = mutableListOf<Placeable>()
        for (measurable in measurableList) {
            val placeable = measurable.measure(constraints)
            width = max(width, placeable.width)
            height += height + placeable.measuredHeight
            placeableList.add(placeable)
        }
        layout(width, height) {
            var currentHeight = 0
            for (placeable in placeableList) {
                placeable.placeRelative(0, currentHeight)
                currentHeight += placeable.height
            }
        }
    }
}